package com.atguigu.java;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author yihu
 * @create 2021-06-10 16:23
 * @email:1057202547@qq.com
 * @dec:
 *
 * Person需要满足如下的要求，方可序列化
 *  * 1.需要实现接口：Serializable  （标识接口 可序列化的）
 *  * 2.当前类提供一个全局常量：serialVersionUID
 *  * 3.除了当前Person类需要实现Serializable接口之外，还必须保证其内部所有属性
 *  *   也必须是可序列化的。（默认情况下，基本数据类型可序列化）
 *  *
 *  *
 *  * 补充：ObjectOutputStream和ObjectInputStream不能序列化static和transient修饰的成员变量
 *
 */
public class Person implements Serializable {
    private  int age;
    private  String name;
    private  static  final  long serialVersionUID = 475463534532L;
    private Account acct;

    public void setAcct(Account acct) {
        this.acct = acct;
    }
    public Account getAcct() {
        return acct;
    }

    public Person(int age, String name, Account acct) {
        this.age = age;
        this.name = name;
        this.acct = acct;
    }

    public Person() {
    }

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }
    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", acct=" + acct +
                '}';
    }
}

class Account implements Serializable{
    public static final long serialVersionUID = 4754534532L;
    private double balance;

    @Override
    public String toString() {
        return "Account{" +
                "balance=" + balance +
                '}';
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public Account(double balance) {

        this.balance = balance;
    }
}

